package cn.mesmile.thread;

/**
 * @author zb
 * @date 2020/12/31 15:44
 * @Description
 */
public class ProducerCustomTest {


}

class Clerk{

    private static int productCount = 10;

    /**
     *  生产
     */
    public static synchronized void product(){

        if(productCount < 20){
            Thread.currentThread().notify();
            productCount++;
            // 当前线程名称
            System.out.println(Thread.currentThread().getName()+" >>>>>>>>> 第："+ productCount +"个产品。");
        }else {
            try {
                Thread.currentThread().wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

    public static synchronized void consume(){

        if(productCount > 0){
            productCount--;
            Thread.currentThread().notify();
            System.out.println("Thread.currentThread().getName() = " + Thread.currentThread().getName());
        }else {

            try {
                Thread.currentThread().wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }

}


class Producer implements Runnable{

    @Override
    public void run() {


    }

}